<?php
	include $setupdata['core_dir']."/modules/payment/gateway/webmoneyclass.php";
	$webmoneyclass = new webmoneyclass;
	
	if ($act=="save"){
		$webmoney_data = array();
		if (isset($_POST["LMI_PAYEE_PURSE"])) $webmoney_data['LMI_PAYEE_PURSE']=$_POST["LMI_PAYEE_PURSE"]; else $webmoney_data['LMI_PAYEE_PURSE']="";

		foreach($webmoney_data as $webmoney_key=>$webmoney_value) {
			if ($webmoney_value == "") $err->AddError(25, "payment_webmoney");
			else $webmoney_data[$webmoney_key] = trim($webmoney_data[$webmoney_key]);
		}

		if (isset($_POST["URL_OK"])) $webmoney_data['URL_OK']=trim($_POST["URL_OK"]); else $webmoney_data['URL_OK']="";
		if (isset($_POST["URL_CANCEL"])) $webmoney_data['URL_CANCEL']=trim($_POST["URL_CANCEL"]); else $webmoney_data['URL_CANCEL']="";
		
		$webmoney = addslashes(serialize($webmoney_data));
		$mysqlclass->mysql_my_query("DELETE FROM `".$setupdata['table_prefix']."local_vars` WHERE 'payment_gateway_webmoney'=`name`", __LINE__, __FILE__);
		$mysqlclass->mysql_my_query("INSERT INTO `".$setupdata['table_prefix']."local_vars` (`id`,`name`,`value`) VALUES ('', 'payment_gateway_webmoney', '".$webmoney."')", __LINE__, __FILE__);
		
		unset($webmoney_tmp);
		unset($webmoney_data);
		unset($webmoney_key);
		unset($webmoney);
	} elseif ($act == "return") {
		$data = $paymentclass->get_gateway_data('webmoney');
		if (isset($_GET['result']) && ($_GET['result'] == "result")){
			$webmoneyclass->order_notify($_POST, 'result');
			if ((isset($data['URL_OK'])) && (strlen($data['URL_OK'])>6)) $str = '"'.$data['URL_OK'].'"';
			else $str = "window.opener.location.href";
		} elseif (isset($_GET['result']) && ($_GET['result'] == "success")){
			$webmoneyclass->order_notify($_POST, 'success');
			if ((isset($data['URL_OK'])) && (strlen($data['URL_OK'])>6)) $str = '"'.$data['URL_OK'].'"';
			else $str = "window.opener.location.href";
		} elseif (isset($_GET['result']) && ($_GET['result'] == "bad")){
			$webmoneyclass->order_cancel();
			if ((isset($data['URL_CANCEL'])) && (strlen($data['URL_CANCEL'])>6)) $str = '"'.$data['URL_CANCEL'].'"';
			else $str = "window.opener.location.href";
		} else {
			$str = "window.opener.location.href";
		}
		print_r('
			<script language="javascript1.4" type="text/javascript">
				url = '.$str.';
				window.opener.location.replace(url);
				window.close();
			</script>
		');
		$mysqlclass->close_db();
		die();
	}
?>